package server;
import server.Data;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.*;

public class Enterprise extends UnicastRemoteObject implements EnterpriceInterface
{
	/*private int ID;//��½ID
	private String name;//��ҵ���
	private int locationNum;//��ҵλ�ñ��
	private int bankAccountID;//��ҵ�����˺�ID
	*/
	private Data data;

	public Enterprise() throws RemoteException
	//int ID,String name,int locationNum,int bankAccountID) 
	{
		/*this.ID=ID;
		this.name=name;
		this.locationNum=locationNum;
		this.bankAccountID=bankAccountID;
		*/
		data=new Data();
	}
/*
	public int getID()
	{
		return ID;
	}
*/
	public String getName(int id)throws RemoteException
	{
		String sql;
		ResultSet rs=null;
		String name=null;
		
		sql="select * from company where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
			name=rs.getString("name");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
			
		return name;
	}
	
	public int getLocationNum(int id)throws RemoteException
	{
		String sql;
		ResultSet rs=null;
		int locationNum=0;
		
		sql="select * from company where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				locationNum=rs.getInt("locationNum");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
			

		return locationNum;
	}
	
	public int getBankAccountID(int id)throws RemoteException
	{
		String sql;
		ResultSet rs=null;
		int bankAccountID=0;
		
		sql="select * from company where id=" + id;
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				bankAccountID=rs.getInt("bankAccountID");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}

		return bankAccountID;
	}
	
	public boolean setBankAccountID(int id,int bankAccountID)throws RemoteException
	{
		String sql;
		int re=0;
		
		sql="update company set bankAccountID = "+bankAccountID+" where id="+id;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	
	}
}
